package com.nondo.dean.order.model.result;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.nondo.dean.common.tool.BeanUtils;
import com.nondo.dean.common.tool.DateUtils;
import com.nondo.dean.order.domain.OrderDetail;
import com.nondo.dean.order.domain.OrderSubject;

public class AppOrderResult {

    /**
     * 订单ID
     */

    private Integer id;
    /**
     * 订单编号
     */
    private String orderCode;

    /**
     * SAP编号
     */
    private String sapCode;

    /**
     * 订单状态
     */
    private String orderStatus;
    
    /**
     * 产品总数
     */
    private Integer total;

    /**
     * 金额合计
     */
    private BigDecimal amount;

    /**
     * 下单时间
     */
    private String createTime;
    
    /**
     * 接单员姓名
     */
    private String orderTakeUser;
    
    /**
     * 接单员联系方式
     */
    private String contactNumber;;

    List<OrderDetailResult> orderDetailList;

    public static class OrderDetailResult {
        /**
         * 产品ID
         */
        private Integer productId;
        /**
         * 产品编码
         */
        private String productCode;

        /**
         * 产品名称
         */
        private String productName;
        
        /**
         * 产品图片
         */
        private String productImage;


        /**
         * 采购数量
         */
        private Integer purchaseQuantity;

        /**
         * 产品价格
         */
        private BigDecimal productPrice;

        /**
         * 产品金额=产品单价*数量
         */
        private BigDecimal amount;

        /**
         * 定制内容
         */
        private String note;

        /**
         * @return the productId
         */
        public Integer getProductId() {
            return productId;
        }

        /**
         * @param productId the productId to set
         */
        public void setProductId(Integer productId) {
            this.productId = productId;
        }

        /**
         * @return the productCode
         */
        public String getProductCode() {
            return productCode;
        }

        /**
         * @param productCode the productCode to set
         */
        public void setProductCode(String productCode) {
            this.productCode = productCode;
        }

        /**
         * @return the productName
         */
        public String getProductName() {
            return productName;
        }

        /**
         * @param productName the productName to set
         */
        public void setProductName(String productName) {
            this.productName = productName;
        }

        /**
         * @return the productImage
         */
        public String getProductImage() {
            return productImage;
        }

        /**
         * @param productImage the productImage to set
         */
        public void setProductImage(String productImage) {
            this.productImage = productImage;
        }

        /**
         * @return the purchaseQuantity
         */
        public Integer getPurchaseQuantity() {
            return purchaseQuantity;
        }

        /**
         * @param purchaseQuantity the purchaseQuantity to set
         */
        public void setPurchaseQuantity(Integer purchaseQuantity) {
            this.purchaseQuantity = purchaseQuantity;
        }

        /**
         * @return the productPrice
         */
        public BigDecimal getProductPrice() {
            return productPrice;
        }

        /**
         * @param productPrice the productPrice to set
         */
        public void setProductPrice(BigDecimal productPrice) {
            this.productPrice = productPrice;
        }

        /**
         * @return the amount
         */
        public BigDecimal getAmount() {
            return amount;
        }

        /**
         * @param amount the amount to set
         */
        public void setAmount(BigDecimal amount) {
            this.amount = amount;
        }

        /**
         * @return the note
         */
        public String getNote() {
            return note;
        }

        /**
         * @param note the note to set
         */
        public void setNote(String note) {
            this.note = note;
        }

        public static OrderDetailResult covertToBean(OrderDetail orderDetail) {
            OrderDetailResult detailResult = new OrderDetailResult();
            BeanUtils.copy(orderDetail, detailResult);
            return detailResult;
        }

    }

    /**
     * @return the id
     */
    public Integer getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * @return the orderCode
     */
    public String getOrderCode() {
        return orderCode;
    }

    /**
     * @param orderCode the orderCode to set
     */
    public void setOrderCode(String orderCode) {
        this.orderCode = orderCode;
    }

    /**
     * @return the sapCode
     */
    public String getSapCode() {
        return sapCode;
    }

    /**
     * @param sapCode the sapCode to set
     */
    public void setSapCode(String sapCode) {
        this.sapCode = sapCode;
    }

    /**
     * @return the orderStatus
     */
    public String getOrderStatus() {
        return orderStatus;
    }

    /**
     * @param orderStatus the orderStatus to set
     */
    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    /**
     * @return the amount
     */
    public BigDecimal getAmount() {
        return amount;
    }

    /**
     * @param amount the amount to set
     */
    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    /**
     * @return the createTime
     */
    public String getCreateTime() {
        return createTime;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getOrderTakeUser() {
        return orderTakeUser;
    }

    public void setOrderTakeUser(String orderTakeUser) {
        this.orderTakeUser = orderTakeUser;
    }

    public String getContactNumber() {
        return contactNumber;
    }

    public void setContactNumber(String contactNumber) {
        this.contactNumber = contactNumber;
    }

    /**
     * @return the prodcutList
     */
    public List<OrderDetailResult> getOrderDetailList() {
        return orderDetailList;
    }

    /**
     * @param prodcutList the prodcutList to set
     */
    public void setOrderDetailList(List<OrderDetailResult> prodcutList) {
        this.orderDetailList = prodcutList;
    }

    private static String YMDHMS = "yyyy-MM-dd HH:mm:ss";

    public static AppOrderResult covertToBean(OrderSubject orderSubject) {
        AppOrderResult orderResult = new AppOrderResult();
        BeanUtils.copy(orderSubject, orderResult);
        Date createDate = orderSubject.getCreateDate();
        if (createDate != null) {
            orderResult.setCreateTime(DateUtils.formatDate(createDate, YMDHMS));
        }
        orderResult.setOrderStatus(getOrderStatus(orderResult.getOrderStatus()));
        return orderResult;
    }

    /**
     * 订单状态描述
     * @param orderStatus->1
     * @return->待收货
     */
    private static String getOrderStatus(String orderStatus) {
        switch (orderStatus) {
            case "1":
                orderStatus = "待支付";
                break;
            case "2":
                orderStatus = "待收货";
                break;
            case "3":
                orderStatus = "已取消";
                break;
            case "4":
                orderStatus = "已完成";
                break;
            default:
                break;
        }
        return orderStatus;
    }

}
